<html lang="en-US" xmlns:th = "http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<link rel="shortcut icon" type="image/x-icon" href="../../favicon.ico"/>
<link rel="stylesheet" href="../../layui/css/layui.css">
<link rel="stylesheet" href="../../css/common.css">
<script src="../../js/jquery.js"></script>
<body>
<!--<script>-->
    <!--var data = $("#wai").val();-->
    <!--var val = eval("("+data+")");-->
    <!--console.log(val);-->


<!--</script>-->

<!--<script th:inline="javascript">-->
    <!--var name = [[${user_name}]];-->
<!--</script>-->
<div class="yadmin-body animated fadeIn">
<form action="" type="post" class="layui-form layui-form-pane">

    <input type="text" id="Id" name="Id" th:value="${wai.getId()}" hidden = "hidden" >


    <div class="layui-form-item">
        <label for="name" class="layui-form-label">
            角色名称
        </label>
        <div class="layui-input-block">
            <input type="text" id="name" name="name"
                   lay-verify="required" lay-vertype="tips"
                   autocomplete="off" class="layui-input" th:value="${wai.getName}" >
        </div>
    </div>
    <div class="layui-form-item">
        <label for="age" class="layui-form-label">
            年龄
        </label>
        <div class="layui-input-block">
            <input type="text" id="age" name="age"
                   lay-verify="required" lay-vertype="tips"
                   autocomplete="off" class="layui-input"  th:value="${wai.getAge()}">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="sex" class="layui-form-label">
            性别
        </label>
        <div class="layui-input-block" id = "sex">
            <input type="radio" name="sex" th:value="0" title="男" th:checked="${wai.getSex()==0}">
            <input type="radio" name="sex" th:value="1" title="女"  th:checked="${wai.getSex()}==1">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="address" class="layui-form-label">
            地址
        </label>
        <div class="layui-input-block">
            <input type="text" id="address" name="address"
                   lay-verify="required" lay-vertype="tips"
                   autocomplete="off" class="layui-input" th:value="${wai.getAddress()}">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="phone" class="layui-form-label">
            电话
        </label>
        <div class="layui-input-block">
            <input type="text" id="phone" name="phone"
                   lay-verify="required" lay-vertype="tips"
                   autocomplete="off" class="layui-input" th:value="${wai.getPhone()}">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="salary" class="layui-form-label">
            基本工资
        </label>
        <div class="layui-input-block">
            <input type="text" id="salary" name="salary"
                   lay-verify="required" lay-vertype="tips"
                   autocomplete="off" class="layui-input" th:value="${wai.getSalary()}">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="password" class="layui-form-label">
            密码
        </label>
        <div class="layui-input-block">
            <input type="password" id="password" name="password"
                   lay-verify="required" lay-vertype="tips"
                   autocomplete="off" class="layui-input" th:value="${wai.getPassword()}">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="price" class="layui-form-label">
            每小时单价
        </label>
        <div class="layui-input-block">
            <input type="text" id="price" name="price"
                   lay-verify="required" lay-vertype="tips"
                   autocomplete="off" class="layui-input" th:value="${wai.getPrice()}">
        </div>
    </div>
    <div class="layui-form-item" pane="">
        <label class="layui-form-label">
            空闲
        </label>
        <div class="layui-input-block">
            <input type="radio" name="isFree"  th:value="1" title="不空闲" th:checked="${wai.getIsFree()==1}">
            <input type="radio" name="isFree"  th:value="0" title="空闲" th:checked="${wai.getIsFree()==0}">
        </div>
    </div>
</form>
    <div class="layui-form-item">
        <div class="layui-input-block" style="margin-left:0;text-align:center;">

            <button class="layui-btn layui-btn-normal"  type="button" onclick="toAjax()">修改</button>
        </div>
    </div>
</div>
<script src="../../layui/layui.js"></script>
<script src="../../js/common.js"></script>

<script>
    layui.config({
        base: '/layui/extend/'
    }).extend({
        formSelects: 'formSelects-v4'
    }).use(['form', 'layer', 'formSelects', 'dtree'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer

    });
    function toAjax() {
        var message="";
                var a = document.getElementsByName("sex");
                var sexd = 0;
                for(var   i=0;   i<a.length;   i++)    {
                    if(a[i].checked){
                        sexd = a[i].value
                    }
                }
                var z = document.getElementsByName("isFree");
                var isF = 0;
                for(var   i=0;   i<z.length;   i++)    {
                    if(z[i].checked){
                        isF = z[i].value
                    }
                }
        $.ajax({
            type: "post",
            url: "/waiter/update/",
            data: {id:$("#Id").val(),name:$("#name").val(),age:$("#age").val(),sex:sexd
                ,address:$("#address").val(),phone:$("#phone").val(),salary:$("#salary").val()
                ,password:$("#password").val(),price:$("#price").val(),isFree:isF},
            dataType: "json",

            success: function (data) {
                if (data.code == '201') {
                    layer.msg("失败", {icon: 5});//失败的表情
                    return;
                } else if (data.code == '0') {
                    layer.msg("成功", {
                        icon: 6,//成功的表情
                        time: 1000 //1秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        location.reload();
                    })
                };
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            }
        });
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
    };


</script>

</body>
</html>